// 主页交互逻辑
document.addEventListener('DOMContentLoaded', function() {
    // 获取DOM元素
    const newGameBtn = document.getElementById('new-game');
    const loadGameBtn = document.getElementById('load-game');
    const rankingBtn = document.getElementById('ranking');
    const modal = document.getElementById('modal');
    const closeBtn = document.querySelector('.close');
    const confirmBtn = document.getElementById('confirm');
    const nicknameInput = document.getElementById('nickname');
    
    // 新游戏按钮点击事件
    newGameBtn.addEventListener('click', function() {
        modal.style.display = 'block';
    });
    
    // 关闭模态框
    closeBtn.addEventListener('click', function() {
        modal.style.display = 'none';
    });
    
    // 点击模态框外部关闭
    window.addEventListener('click', function(event) {
        if (event.target === modal) {
            modal.style.display = 'none';
        }
    });
    
    // 确认按钮点击事件
    confirmBtn.addEventListener('click', function() {
        const nickname = nicknameInput.value.trim();
        if (nickname) {
            // 存储昵称并跳转到游戏页
            localStorage.setItem('playerName', nickname);
            window.location.href = 'game.html';
        }
    });
    
    // 加载游戏按钮点击事件
    loadGameBtn.addEventListener('click', function() {
        // 实现加载游戏逻辑
        alert('加载游戏功能将在后续实现');
    });
    
    // 排行榜按钮点击事件
    rankingBtn.addEventListener('click', function() {
        window.location.href = 'ranking.html';
    });
});